<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>区域管理</title>
<%@ include file="/common/header/meta.jsp"%>
<%@ include file="/common/header/script.jsp"%>
<script type="text/javascript">
	var $tg;
	$(function() {
		$tg = $("#tg").treegrid({
			url: base.contextPath+"/sysmgr/area/treegrid_areas.do",
			title: '<span style="font-weight:normal;color:#666;">系统基础配置-->系统管理-->区域管理</span>',
			idField: 'id', treeField: 'areaName',parentField: 'parentAreaId',
			remoteSort: false, fit: true,toolbar: '#toolbars', striped:true, rownumbers: true,
			frozenColumns: [[
	             { field: 'ck', checkbox: true },
	             { field: 'id', title: 'ID', width: 50 }
	        ]],
	        columns: [[
            	{ field: 'areaName', title: '区域名称', width: 220, sortable: true },
            	{ field: 'areaNumber', title: '区域区号', width: 100, sortable: true },
            	{ field: 'areaCode', title: '区域代码', width: 100, sortable: true },
            	{ field: 'countryCode', title: '国家代码', width: 100, sortable: true },
            	{ field: 'areaType', title: '区域类型', width: 100, sortable: true },
            	{ field: 'remark', title: '备注', width: 220, sortable: true }
	        ]],
	        enableHeaderClickMenu: false,enableHeaderContextMenu: false,
		}) ;
	});
	
	function form_edit(form) {
		var form_url = base.contextPath+"/sysmgr/area/area_form.do" ;
		if("E" == form) {
			var node = $tg.treegrid('getSelected');
			if (node) {
				form_url = base.contextPath+"/sysmgr/area/area_form.do?id="+node.id ;
			} else {
				alertify.warning("请选择一条记录！"); return ;
			}
		}
		var $d = $.easyui.showDialog({
			href: form_url, title: "表单", iniframe: false, topMost: true, width: 740 , height: 400,
	        enableApplyButton: false, enableCloseButton: false,  enableSaveButton: false,
	        buttons : [ 
	          { text : '确定', iconCls : 'ext_save', handler : function() { $.easyui.parent.submitForm($d, $tg) ; } },
	          { text : '关闭', iconCls : 'ext_cancel', handler : function() { $d.dialog('destroy'); } }
	       	]
	    });
	}
	
	function del() {
		var node = $tg.treegrid('getSelected');
		if(node){
			$.messager.confirm("您确定要进行该操作？", function (c) { 
				if(c) {
					$.easyui.loading({ msg: "数据删除中，请稍等..." });
					$.post(base.contextPath+"/sysmgr/area/delete.do", {id:node.id}, function(result) {
						if (result.status) {
							$tg.treegrid('reload') ;
							$.easyui.loaded(); alertify.success(result.msg);
						} else {
							$.easyui.loaded();alertify.error(result.msg);
						}
					}, 'json').error(function(){$.easyui.loaded();});
				}
			});
		} else {
			alertify.warning("请选择一条记录！");
		}
	}

</script>
</head>

<body>

	<div id="tg">
		<div id="toolbars">
            <a onClick="form_edit('A');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_add'">添加</a>
            <a onClick="form_edit('E');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_edit'">编辑</a>
            <a onClick="del();" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_remove'">删除</a>
            <a onclick="$tg.treegrid('reload');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_reload'">刷新</a>
        </div>
	</div>

</body>
</html>